package com.sskj.ffex.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.ffex.MyAppLication;
import com.sskj.ffex.R;
import com.sskj.ffex.common.App;
import com.sskj.ffex.common.Constants;
import com.sskj.ffex.common.rxbus2.RxBus;
import com.sskj.ffex.m.HttpConfig;
import com.sskj.ffex.m.bean.HttpData;
import com.sskj.ffex.m.bean.PayWayBean;
import com.sskj.ffex.m.bean.PublishPrice;
import com.sskj.ffex.m.bean.rxbus.TabChange;
import com.sskj.ffex.m.http.JsonCallBack;
import com.sskj.ffex.p.base.BasePresenter;
import com.sskj.ffex.utils.ToastUtil;
import com.sskj.ffex.v.activity.FabiPublishActivity;

import java.util.ArrayList;

/**
 * ProjectName：bfex
 * DESC: (类描述)
 * Created by 李岩 on 2018/7/3 0003
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class FabiPublishPresenter extends BasePresenter<FabiPublishActivity> {
    public void requsetPayWayList() {
        OkGo.<HttpData<ArrayList<PayWayBean>>>post(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST)
                .params("account", MyAppLication.getAccount())
                .execute(new JsonCallBack<HttpData<ArrayList<PayWayBean>>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<ArrayList<PayWayBean>>> response) {
                        mView.onPayWaySuccess(response.body());
                    }

                    @Override
                    public void onError(Response<HttpData<ArrayList<PayWayBean>>> response) {
                        super.onError(response);
                        mView.onHttpFail();
                    }
                });
    }

    /**
     * @param type       pmma求购/sell出售
     * @param sumCount
     * @param lowCount
     * @param hightCount
     * @param unitPrice
     * @param remark
     */
    public void requsetPublish(String type, String sumCount, String lowCount, String hightCount, String unitPrice, int payWx, int payAli, int payBank, int paypal, String remark) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.PUBLISH)
                .params("account", MyAppLication.getAccount())
                .params("trans_num", sumCount)
                .params("min_price", lowCount)
                .params("max_price", hightCount)
                .params("price", unitPrice)
                .params("pay_wx", payWx)
                .params("pay_alipay", payAli)
                .params("paypal", paypal)
                .params("pay_backcard", payBank)
//                .params("notes", TextUtils.isEmpty(remark)? App.INSTANCE.getString(R.string.strFabiPublishPresenter210):remark)
                .params("type", type)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<Object>> response) {
                        ToastUtil.getInstance(MyAppLication.getApplication()).showMessage(App.INSTANCE.getString(R.string.strFabiPublishPresenter212));
                        if (response.body().getStatus() == 200) {
                            RxBus.getDefault().send(Constants.FABI_DATING_REFRESH);
                            RxBus.getDefault().post(new TabChange("pmma".equals(type)));
                            mView.finish();
                        }
                    }
                });

    }

    public void requestUnitPrice() {
        OkGo.<HttpData<PublishPrice>>get(HttpConfig.BASE_URL + HttpConfig.PUBLISH_PRICE)
                .execute(new JsonCallBack<HttpData<PublishPrice>>() {
                    @Override
                    protected void _onSuccess(Response<HttpData<PublishPrice>> response) {
                        mView.onPublishPriceSuccess(response.body().getData().price);
                    }
                });
    }
}
